package com.unique.flyme.match.netServiceTools.meizuApi;

import android.content.Context;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONObject;

/**
 * Description:
 * User: Dream_Coder(chenchen_839@126.com)
 * Date: 2015-10-25
 * Time: 00:58
 */
public class JsonSendMeizuHelper extends BaseMeizuSendHelper {

    public JsonSendMeizuHelper(Context context) {
        super(context);
    }

    public void getPostJsonObjectResponse(String url, JSONObject jsonObject, final ApiUtils.OnSuccessLoginListener success,final ApiUtils.OnFailedLoginListener fail) {
        getJsonObjectResponse(Request.Method.POST, url, jsonObject, success, fail);
    }

    public void getGetJsonObjectResponse(String url, JSONObject jsonObject, final ApiUtils.OnSuccessLoginListener success,final ApiUtils.OnFailedLoginListener fail) {
        getJsonObjectResponse(Request.Method.GET, url, jsonObject, success, fail);
    }

    private void getJsonObjectResponse(int method, String url, JSONObject jsonObject, final ApiUtils.OnSuccessLoginListener success,final ApiUtils.OnFailedLoginListener fail) {
        JsonObjectRequest request = new JsonObjectRequest(method, url, jsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                success.onSuccessHandler(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.i("ApiUtils",volleyError.getMessage());
                fail.onFailedHandler(volleyError.getMessage());
            }
        });
        getRequestQueue().add(request);
    }
}
